/**
 * Definition for singly-linked list.
 * function ListNode(val) {
 *     this.val = val;
 *     this.next = null;
 * }
 */
/**
 * @param {ListNode} l1
 * @param {ListNode} l2
 * @return {ListNode}
 */
var addTwoNumbers = function(l1, l2) { 
    //  if (l1 === null && l2 === null) {
    //   return;
    // } 
    // else {
    //   l1 = l1 === null ? new ListNode(0) : l1;
    //   l2 = l2 === null ? new ListNode(0) : l2;
    // }
      var value1 = l1.val;
      var value2 = l2.val;    
      var sum = value1 + value2;
      var ten = sum / 10 >= 1 ? 1 : 0; 
      var one = sum % 10;
      var linknode = new ListNode(one);
      if (l1.next === null && l2.next === null) {
        if (ten !== 0){
          linknode.next = new ListNode(ten);
          return linknode;
        }
        return linknode;
      } 
      else {
        l1.next = l1.next === null ? new ListNode(0) : l1.next;
        l2.next = l2.next === null ? new ListNode(0) : l2.next;
      }
      l1.next.val += ten;
      linknode.next = addTwoNumbers(l1.next, l2.next);

      return linknode;
};